package com.lyrcsoft.handler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class RouterConfiguration {
    @Bean
    RouterFunction<ServerResponse> userRouterFunction(UserHandler userHandler) {
        return RouterFunctions.nest(RequestPredicates.path("/user"),
            RouterFunctions.route(RequestPredicates.GET("/getAllUser"), userHandler::getAllUsers)
                .andRoute(RequestPredicates.POST("/addUser"), userHandler::addUser)
                .andRoute(RequestPredicates.DELETE("/{userId}"), userHandler::deleteUser));
    }
}
